//################################
// 版权所有：鸽子游戏俱乐部
// 系统名称：鸽子游戏俱乐部-移动版
// 文件名称：resetPwdService.js
// 创建时间：2017年08月13日
// 创建人员：Lemo
// 功能说明：reset password service
//################################
'use strict';

import Config from '../common/config';
import CommonFunc from '../common/commonFunc';

import { request } from '../utils/requestUtil';

function resetPwd(originpwd, newpwd, dcheckpwd) {
    return new Promise((resolve, reject) => {
        let params = [];
        params.timeout = 5000;
        params.method = 'post';
        params.postType = 'json';
        params.url = CommonFunc.getUrlConfig('savePassword', 'login');
        let formData = new FormData();
        formData.append('oldPass',originpwd);
        formData.append('newPass',newpwd);
        formData.append('newPass2',dcheckpwd);
        params.params = formData;

        request(params)
        .then((responseData) => {
            if (responseData.code=='200') {
                var result = {
                    code: responseData.code,
                    data: responseData.data,
                };

                resolve(result);
            }
            else {
                var result = {
                    code: responseData.code,
                    message: responseData.info,
                };

                reject(result);
            }
        })
        .catch((error) => {
            reject(error);
        });
    });
}

module.exports = {
    resetPwd,
}